package com.bdqn.Practice.controller;

import com.alibaba.fastjson.JSON;
import com.bdqn.Practice.pojo.SysRole;
import com.bdqn.Practice.service.SysRoleService;
import com.bdqn.Practice.util.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "role")
public class SysRoleMapperController {
    @Resource
    SysRoleService sysRoleService;

    @GetMapping(value = "simpleList")
    public void simpleList(Model model, HttpServletResponse response) throws IOException {
        List<SysRole> list=sysRoleService.roleName();
        String resultJson= JSON.toJSONString(list);
        response.getWriter().print(resultJson);
        response.getWriter().flush();
        response.getWriter().close();
    }
    @GetMapping(value = "list")
    public String list(Model model,@RequestParam(defaultValue = "1") Integer pageIndex){
        Page page=new Page();
        page.setTotalCount(sysRoleService.count());
        page.setCurrentPageNo(pageIndex);
        List<SysRole>list=sysRoleService.roleList(page.getCurrentPageNo(),page.getPageSize());
        model.addAttribute("roleList",list);
        return "sysRole/list";
    }
}
